package org.wyn.service.impl;

import org.wyn.mongodb.bean.User;
import org.wyn.mongodb.bean.UserDetail;
import org.wyn.mongodb.dao.impl.AlbumDao;
import org.wyn.mongodb.dao.impl.MessageDao;
import org.wyn.mongodb.dao.impl.UserDao;
import org.wyn.mongodb.dao.impl.UserDetailDao;
import org.wyn.mongodb.dao.impl.VisitHistoryDao;
import org.wyn.service.IRegisterSerivce;

import com.google.inject.Inject;


public class RegisterServiceImpl implements IRegisterSerivce {
	
	@Override
	public boolean userExist(String userName) {
		if(userDao.findOne("userName", userName) != null)
			return true;
		else
			return false;
	}
	
	@Override
	public boolean registerNewUser(User user) {
		userDao.save(user);
		//建索引
		userDao.ensureIndexes();
		//新建UserDetail
		UserDetail ud = new UserDetail();
		ud.setUserName(user.getUserName());
		ud.setRealName(user.getRealName());
		ud.setGender(user.getGender());
		userDetailDao.save(ud);
		userDetailDao.ensureIndexes();
		//新建VisitHistory(最近访问历史)
		visitHistoryDao.createHistory(user.getUserName());
		//新建留言
		messageDao.createMessage(user.getUserName());
		//新建头像相册
		albumDao.createPortraitAlbum(user.getUserName());
		return true;
	}
	@Inject
	private UserDao userDao = null;
	@Inject
	private UserDetailDao userDetailDao;
	@Inject
	private VisitHistoryDao visitHistoryDao;
	@Inject
	private AlbumDao albumDao;
	@Inject
	private MessageDao messageDao;
	public UserDao getUserDao() {
		return userDao;
	}
	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
	public static void main(String[] args) {
		double value = 0.0769;
		double similVal = 0;
		System.out.println(Math.sqrt(value) * 2 + similVal);
	}

	public UserDetailDao getUserDetailDao() {
		return userDetailDao;
	}

	public void setUserDetailDao(UserDetailDao userDetailDao) {
		this.userDetailDao = userDetailDao;
	}

	public VisitHistoryDao getVisitHistoryDao() {
		return visitHistoryDao;
	}

	public void setVisitHistoryDao(VisitHistoryDao visitHistoryDao) {
		this.visitHistoryDao = visitHistoryDao;
	}

	public MessageDao getMessageDao() {
		return messageDao;
	}

	public AlbumDao getAlbumDao() {
		return albumDao;
	}

	public void setAlbumDao(AlbumDao albumDao) {
		this.albumDao = albumDao;
	}

	public void setMessageDao(MessageDao messageDao) {
		this.messageDao = messageDao;
	}
	
}
